package tt;

import com.google.appengine.api.users.User;
import com.google.appengine.api.users.UserService;
import com.google.appengine.api.users.UserServiceFactory;

import com.googlecode.objectify.Objectify;
import com.googlecode.objectify.ObjectifyFactory;
import com.googlecode.objectify.ObjectifyService;
import com.googlecode.objectify.Query;

import tt.Appuser;

public enum Vuser {
	INSTANCE;
	// private PersistenceManager pm = PMF.get().getPersistenceManager();
	public ObjectifyFactory ofacty = ObjectifyService.factory();
	public Objectify ofy = ofacty.begin();
	UserService userService = UserServiceFactory.getUserService();
	User user = userService.getCurrentUser();

	private Vuser() {
	}

	public Query<Appuser> getUsersz(String owner) {		
		ofy.getFactory().register(Appuser.class);
		Query<Appuser> q = ofy.query(Appuser.class).filter("owner ==", owner);
		return q;
	}

	public void add(Appuser usertoadd) {
		synchronized (this) {
			try {
				ofy.getFactory().register(Appuser.class);
				ofy.put(usertoadd);
			} finally {

			}
		}
	}

	public void remove(Long idint) {
		ofy.getFactory().register(Appuser.class);
		ofy.delete(getById(idint));
	}

	public Appuser getById(Long key) {
		ofy.getFactory().register(Appuser.class);
		Appuser usertoremove = ofy.get(Appuser.class, key);
		return usertoremove;
	}
}
